package src.accenture.com.entity;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedNativeQueries;
import javax.persistence.NamedNativeQuery;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@NamedQueries( { @NamedQuery(name = "MblRegistration.findAll", query = "select o from MblRegistration o") })
@Table(name = "MBL_REGISTRATION")
@NamedNativeQueries({ 
    @NamedNativeQuery(name = "MblRegistration.insertRegistration", 
                                         query = 
                                         "INSERT INTO MBL_REGISTRATION(EMP_ID \n" + 
                                                  ", TYPE_ID \n" +
                                                  ", FROMDATE \n" +
                                                  ", TODATE \n" +
                                                  ", APPROVALSTATUS \n" +
                                                  ", APPROVALDATE \n" +
                                                  ", APPROVALBY \n" +
                                                  ", DESCRIBE \n" +
                                                  ", FROMTIME \n" +
                                                  ", TOTIME \n" +
                                                  ", REASON) \n" +
                                          " VALUES (?emp_id \n" +
                                                  ", ?type_id \n" +
                                                  ", ?fromdate \n" +
                                                  ", ?todate \n" +
                                                  ", ?approvalstatus \n" +
                                                  ", ?approvaldate \n" +
                                                  ", ?approvalby \n" +
                                                  ", ?describe \n" +
                                                  ", ?fromtime \n" +
                                                  ", ?totime \n" +
                                                  ", ?reason) \n" 
                                         )
,          
    @NamedNativeQuery(name = "MblRegistration.updateRegistration", 
                                         query = 
                                         "UPDATE MBL_REGISTRATION SET \n" + 
                                                  " FROMDATE = ?newfromdate \n" +
                                                  ", TODATE = ?newtodate \n" +
                                                  ", FROMTIME = ?fromtime \n" +
                                                  ", TOTIME = ?totime \n" +
                                                  ", REASON = ?reason  \n" +
                                         " WHERE EMP_ID = ?emp_id \n" +
                                                  "AND TYPE_ID = ?type_id \n" +
                                                  "AND FROMDATE = ?fromdate \n" +
                                                  "AND TODATE = ?todate \n" +
                                                  "AND APPROVALSTATUS = 0 " 
                      )
,          
    @NamedNativeQuery(name = "MblRegistration.deleteRegistration", 
                                         query = 
                                         "DELETE FROM MBL_REGISTRATION \n" + 
                                         "WHERE EMP_ID = ?emp_id \n" +
                                           "AND TYPE_ID = ?type_id \n" +
                                           "AND FROMDATE = ?fromdate \n" +
                                           "AND TODATE = ?todate \n" +
                                           "AND APPROVALSTATUS = 0 " 
                      )    
,  
    @NamedNativeQuery(name = "MblRegistration.getRegistration", 
                                         query = 
                                         "SELECT EMP_ID, TYPE_ID, FROMDATE, TODATE, \n" + 
                                             "APPROVALSTATUS, APPROVALDATE, FROMTIME, TOTIME, REASON\n" +                                          
                                         "FROM 	MBL_REGISTRATION \n" + 
                                         "WHERE	EMP_ID = ?empid \n" +
                                             "AND TYPE_ID = ?typeid \n" +
                                             "AND APPROVALSTATUS = ?approvalstatus \n" + 
                                         "ORDER BY TODATE DESC \n",                                         
                                         resultClass = MblRegistration.class)
        } )
@IdClass(MblRegistrationPK.class)
public class MblRegistration implements Serializable {
    @Temporal(TemporalType.DATE)
    private Date approvaldate;
    @Column(nullable = false)
    private int approvalstatus;
    @Column(length = 4000)
    private String describe;
    @Id
    @Column(name = "EMP_ID", nullable = false, length = 10, insertable = false, updatable = false)
    private String empId;
    @Id
    @Temporal(TemporalType.DATE)
    @Column(nullable = false)
    private Date fromdate;
    @Column(nullable = false, length = 8)
    private String fromtime;
    @Column(length = 4000)
    private String reason;
    @Id
    @Temporal(TemporalType.DATE)
    @Column(nullable = false)
    private Date todate;
    @Column(nullable = false, length = 8)
    private String totime;
    @Id
    @Column(name = "TYPE_ID", nullable = false, length = 10, insertable = false, updatable = false)
    private String typeId;
    @ManyToOne
    @JoinColumn(name = "EMP_ID")
    private MblEmployee mblEmployee;
    @ManyToOne
    @JoinColumn(name = "APPROVALBY")
    private MblEmployee mblEmployee1;
    @ManyToOne
    @JoinColumn(name = "TYPE_ID")
    private MblHolidaytype mblHolidaytype;

    public MblRegistration() {
    }

    public MblRegistration(MblEmployee mblEmployee1, Date approvaldate, int approvalstatus, String describe,
                           MblEmployee mblEmployee, Date fromdate, String fromtime, String reason, Date todate,
                           String totime, MblHolidaytype mblHolidaytype, String empId, String typeId) {
        this.mblEmployee1 = mblEmployee1;
        this.approvaldate = approvaldate;
        this.approvalstatus = approvalstatus;
        this.describe = describe;
        this.mblEmployee = mblEmployee;
        this.fromdate = fromdate;
        this.fromtime = fromtime;
        this.reason = reason;
        this.todate = todate;
        this.totime = totime;
        this.mblHolidaytype = mblHolidaytype;
        this.empId = empId;
        this.typeId = typeId;
    }

    public MblRegistration(MblEmployee mblEmployee1, Date approvaldate, int approvalstatus, String describe,
                           MblEmployee mblEmployee, Date fromdate, String fromtime, String reason, Date todate,
                           String totime, MblHolidaytype mblHolidaytype) {
        this.mblEmployee1 = mblEmployee1;
        this.approvaldate = approvaldate;
        this.approvalstatus = approvalstatus;
        this.describe = describe;
        this.mblEmployee = mblEmployee;
        this.fromdate = fromdate;
        this.fromtime = fromtime;
        this.reason = reason;
        this.todate = todate;
        this.totime = totime;
        this.mblHolidaytype = mblHolidaytype;
    }
   
    public Date getApprovaldate() {
        return approvaldate;
    }

    public void setApprovaldate(Date approvaldate) {
        this.approvaldate = approvaldate;
    }

    public int getApprovalstatus() {
        return approvalstatus;
    }

    public void setApprovalstatus(int approvalstatus) {
        this.approvalstatus = approvalstatus;
    }

    public String getDescribe() {
        return describe;
    }

    public void setDescribe(String describe) {
        this.describe = describe;
    }

    public String getEmpId() {
        return empId;
    }

    public void setEmpId(String empId) {
        this.empId = empId;
    }

    public Date getFromdate() {
        return fromdate;
    }

    public void setFromdate(Date fromdate) {
        this.fromdate = fromdate;
    }

    public String getFromtime() {
        return fromtime;
    }

    public void setFromtime(String fromtime) {
        this.fromtime = fromtime;
    }

    public String getReason() {
        return reason;
    }

    public void setReason(String reason) {
        this.reason = reason;
    }

    public Date getTodate() {
        return todate;
    }

    public void setTodate(Date todate) {
        this.todate = todate;
    }

    public String getTotime() {
        return totime;
    }

    public void setTotime(String totime) {
        this.totime = totime;
    }

    public String getTypeId() {
        return typeId;
    }

    public void setTypeId(String typeId) {
        this.typeId = typeId;
    }

    public MblEmployee getMblEmployee() {
        return mblEmployee;
    }

    public void setMblEmployee(MblEmployee mblEmployee) {
        this.mblEmployee = mblEmployee;
        if (mblEmployee != null) {
            this.empId = mblEmployee.getEmpId();
        }
    }

    public MblEmployee getMblEmployee1() {
        return mblEmployee1;
    }

    public void setMblEmployee1(MblEmployee mblEmployee1) {
        this.mblEmployee1 = mblEmployee1;
    }

    public MblHolidaytype getMblHolidaytype() {
        return mblHolidaytype;
    }

    public void setMblHolidaytype(MblHolidaytype mblHolidaytype) {
        this.mblHolidaytype = mblHolidaytype;
        if (mblHolidaytype != null) {
            this.typeId = mblHolidaytype.getTypeId();
        }
    }
}
